<?php
    $name = $_POST['name'];
    $desc = $_POST['desc'];
    $type = $_POST['type'];
    $year = $_POST['year'];


    $sql = mysqli_connect("localhost", "root", "rabarip", "movies");
    if(mysqli_connect_errno()){
        mysqli_query($sql,"CREATE DATABASE `movies`");
        echo 'create database movies successfully';
        $sql = mysqli_connect("localhost", "root", "rabarip", "movies");
    }else{
        echo 'connect to db movies successfully';
    }
    
    if(mysqli_query($sql,"INSERT INTO `film_list` (`name`,`desc`,`type`,`year`) values ('$name','$desc','$type','$year');")){
        echo 'Insert value to database successfully';
    }else{
        mysqli_query($sql,"CREATE TABLE  `film_list` (
        `name` VARCHAR( 30 ) NOT NULL ,
        `desc` VARCHAR( 1000 ) NULL ,
        `type` VARCHAR( 10 ) NOT NULL ,
        `year` INT( 4 ) NOT NULL ,
       PRIMARY KEY (  `name` )
       )");
        if(mysqli_query($sql,"INSERT INTO `film_list` (`name`,`desc`,`type`,`year`) values ('$name','$desc','$type','$year');")){
           echo 'create table and insert value to table successfully'; 
        }
    }
    
